package iscript.gameFramework.IsoLibarys.display 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import iscript.coreFramework.displays.DragObject;

	public class IsoScenePane 
	{
		
		public function IsoScenePane(target:Sprite,maskSprite:Sprite) 
		{
			_target = target;
			_maskSprite = maskSprite;
		}
		private var _maskSprite:Sprite;
		private var _bm:Bitmap;
		private var _target:Sprite
		private var _containerWidth:Number;
		private var _containerHeight:Number;
		//public function updateMask(containerWidth:Number, containerHeight:Number, maskWidth:Number, maskHeight:Number):void {}
			
			
		private var _scrollDrag:Boolean;
		public function set scrollDrag(value:Boolean):void {
				_scrollDrag = value;
				
				if (value) {
					_target.addEventListener(MouseEvent.MOUSE_DOWN, _startDrag);
					
					_target.addEventListener(Event.ADDED_TO_STAGE,_addToStageLogic)
					

					//_target.stage.addChild
					
					//DragObject.getInstance().add(_target);
					
					}else {
					//DragObject.getInstance().remove(_target);
						
						
						}
				
				
			}
			
			private function _addToStageLogic(e:Event):void 
			{
					_target.stage.addEventListener(MouseEvent.MOUSE_OVER, _sceneDragLogic);
					_target.stage.addEventListener(MouseEvent.MOUSE_UP, _stopsceneDragLogic);
			}
			
			private function _stopsceneDragLogic(e:MouseEvent):void 
			{
				_target.stopDrag();
			}
			
		private function _sceneDragLogic(e:MouseEvent):void {
		 
				e.updateAfterEvent();
			  
		    } 
			
		public function get scrollDrag():Boolean {
				return _scrollDrag;
			}
		
	    private var _allowDrag:Boolean;	
		private function _startDrag(e:MouseEvent):void {
			
			//if (maskWidth >= containerWidth || maskHeight >= containerHeight) return;
			
			    _allowDrag = false;
				 /*_target.startDrag(false, new Rectangle(_maskSprite.x - (_target.width - _bm.width),
				                                       _maskSprite.y - (_target.height - _bm.height),
													   _target.width - _bm.width,
													   _target.height - _bm.height));*/
													   
													   
			/*  var  rect:Rectangle = new Rectangle(_maskSprite.x - (_containerWidth - _bm.width),
												  _maskSprite.y - (_containerHeight- _bm.height),
												  _containerWidth- _bm.width,
												  _containerHeight - _bm.height);*/
												  
		        var rect:Rectangle = new Rectangle(_maskSprite.x - (_target.width - _bm.width),
												   _maskSprite.y - (_target.height - _bm.height),
												   _target.width - _bm.width,
												   _target.height - _bm.height);
												  
				  rect.x -= 150
				  rect.y -=150
				  rect.width += 300;
				  rect.height += 300;
				 _target.startDrag(false, rect);
				
				 
			}
			
			
		 
		public function mask(containerWidth:Number, containerHeight:Number, maskWidth:Number, maskHeight:Number):void {
			//if (maskWidth >= containerWidth || maskHeight >= containerHeight) return;
			
			
			 _containerWidth = containerWidth;
			 _containerHeight = containerHeight;
			
			
			_bm= new Bitmap( new BitmapData(maskWidth, maskHeight, false, 0x000000));
			//_bm.alpha = 0.5;
			_maskSprite.addChild(_bm);
			_target.mask = _maskSprite;
			
			_maskSprite.x = containerWidth / 2 - _bm.width / 2;
			_maskSprite.y = containerHeight / 2 - _bm.height / 2;
			 
			}
		
		
	    public function aglin(aglin:String):void {
			
			
			}
		
		
		
	}

}